home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)event_post.c V1.14 3/13/95";
- #endif
- /*
- | file name - event_post.c
- |===================================================================
- |
- | Example program that shows how to use event request post
- | routine 'VUerBoundaryEventPost()' to detect the rectangle
- | edge and object edge events. It also shows how to include
- | the V_BUTTONPRESS and V_KEYPRESS winevents when posting
- | the event request.
- |
- | This example let you choose one of five sample event request
- | post methods by a DV-Draw created menu object. Three different
- | polygons with different attributes are used to illustrate the
- | functionality of each event request post method.
- |
- | Type 'q' or 'Q' to quit this program.
- |
- |===================================================================
- */
- #include <windows.h>
- #include "std.h"
- #include "dvstd.h"
- #include "VOstd.h"
- #include "dvtools.h"
- #include "dvinteract.h"
- #include "Tfundecl.h"
- #include "VOfundecl.h"
- #include "VUerfundecl.h"
- //#include "GRkeysym.h" /* Includes GRkeysymdef.h */
-
- /* Define the different event request post method */
- #define RECT_EDGE 1 /* Base on obj's bounding box */
- #define OBJECT_EDGE 2 /* Base on obj's edge */
- #define RECT_EDGE_BUTTON_PRESS 3 /* Bounding box + mouse button*/
- #define OBJECT_EDGE_KEY_PRESS 4 /* Obj edge + key press */
- #define RECT_EDGE_BUTTON_KEY_PRESS 5 /* Bounding box + mouse Button
- | + key press */
-
- /* Define the characteristics of the three polygons */
- #define NUM_OF_TEST_POLY 3
- #define EDGE_POLY 0
- #define TRANSPARENT_POLY 1
- #define FILL_POLY 2
-
- #define VCAST (INT (*)(OBJECT, EVENT_REQUEST, INT, OBJECT, ADDRESS))
-
- /* Information to be passed on to the service routine HandleInput() */
- typedef struct
- {
- DRAWPORT drawport;
- OBJECT poly[NUM_OF_TEST_POLY];/* Array for the three polygons */
- OBJECT mark[NUM_OF_TEST_POLY];/* Mark object for each polygon */
- float *data_ptr;
- int post_mode;
- } INFO;
-
-
- /* Define the state for the polygons' mark objects */
- LOCAL int init_state[]= {EDGE, EDGE, EDGE};
- LOCAL int mark_state[]= {EDGE_WITH_FILL, EDGE_WITH_FILL, EDGE_WITH_FILL};
-
- #define BUTTON_1 1 /* default select key */
- #define BUTTON_2 2
- #define BUTTON_3 3
- #define XK_a 0x061
- #define XK_s 0x073
- #define XK_z 0x07a
- #define XK_b 0x062
- #define XK_space 0x020
- #define XK_semicolon 0x03b
-
-
- /* Define the buttonsyms */
- LOCAL ULONG buttonsyms[]= {BUTTON_1, BUTTON_2, BUTTON_3, V_END_OF_LIST};
-
- /* Define the keysyms, keysyms are defined in GRkeysymdef.h
- | Define key string 's z' in keysyms_1 and 'ab;' in keysyms_2 */
- LOCAL ULONG keysyms_1[] = {XK_s, XK_space, XK_z, V_END_OF_LIST};
- LOCAL ULONG keysyms_2[] = {XK_a, XK_b, XK_semicolon, V_END_OF_LIST};
-
- LOCAL OBJECT bound_box[NUM_OF_TEST_POLY]; /* Bounding boxes for polygons */
-
- /* Functions defined in event_post.c */
- /***************** Begin Function Declarations *************/
- LOCAL int PostEvent V_P_((OBJECT client, EVENT_REQUEST er, int label,
- OBJECT loc, ADDRESS args));
- LOCAL int DrawMark V_P_((OBJECT client, EVENT_REQUEST er, int label,
- OBJECT loc, ADDRESS args));
- LOCAL int ClearMark V_P_((OBJECT client, EVENT_REQUEST er, int label,
- OBJECT loc, ADDRESS args));
- LOCAL void GetBoundBox V_P_((INFO *info, OBJECT bound_box[]));
- LOCAL void RectEdge V_P_((INFO *info));
- LOCAL void ObjectEdge V_P_((INFO *info));
- LOCAL void RectEdge_ButtonPress V_P_((INFO *info));
- LOCAL void ObjectEdge_KeyPress V_P_((INFO *info));
- LOCAL void RectEdge_ButtonKeyPress V_P_((INFO *info));
- /***************** End Function Declarations *************/
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc=0;
- CHAR **argv;
- /* argv[1] - device name (default is DVDEVICE) */
-
- OBJECT screen, location;
- VIEW view;
- int key;
-
- /* Input object related variables */
- OBJECT menu;
- ADDRESS *vdplist;
- INFO info;
- int numvars;
- LOCAL RECTANGLE whole_world = {XMIN, YMIN, XMAX, YMAX};
-
- make_argv(&argc,&argv,GetCommandLine());
- /*
- * Initialize DV-Tools, possibly using user's search path
- */
- TInit ((char *) NULL, (char *) NULL); /* Use config var DVPATH */
-
- /*
- * Open the indicated device, load the view, rebind all its variables
- * to a single data value, and set up the drawport.
- */
- if (argc > 1)
- screen = TscOpenSet (argv[1], (char *) NULL,
- V_X_EXPOSURE_BLOCK, YES, V_END_OF_LIST);
- else
- screen = TscOpenSet ((char *) NULL, (char *) NULL,
- V_X_EXPOSURE_BLOCK, YES, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- exit (EXIT_ERR);
- }
-
- /* Load the static View and extract object info */
- view = TviLoad ("event_post.v");
- info.poly[EDGE_POLY] = TdrGetNamedObject (TviGetDrawing (view),
- "py_edge.obj");
- info.poly[TRANSPARENT_POLY] = TdrGetNamedObject (TviGetDrawing (view),
- "py_trans.obj");
- info.poly[FILL_POLY] = TdrGetNamedObject (TviGetDrawing (view),
- "py_fill.obj");
- info.mark[EDGE_POLY] = TdrGetNamedObject (TviGetDrawing (view),
- "mark_edge.obj");
- info.mark[TRANSPARENT_POLY] = TdrGetNamedObject (TviGetDrawing (view),
- "mark_trans.obj");
- info.mark[FILL_POLY] = TdrGetNamedObject (TviGetDrawing (view),
- "mark_fill.obj");
- info.drawport = TdpCreateStretch (screen, view, (RECTANGLE *) NULL,
- &whole_world);
-
- /* Get bounding box for each poly */
- GetBoundBox (&info, bound_box);
-
- /* Get the menu input objects and its variable */
- menu = TdrGetNamedObject (TviGetDrawing (view), "menu_input.obj");
- VOinGetVarList (menu, &vdplist, &numvars);
- info.data_ptr = (float *) TdsvGetBuffer (TvdGetDataSourceVariable (vdplist[0]));
-
- /* Post service result request for the menu input object.
- | Key bindings are defined in the view */
- VUerServiceResultPost ((OBJECT) 1, (VUERFCNFUNPTR)PostEvent,
- (ADDRESS) & info,
- (int)sizeof (info), menu, (int) INPUT_DONE, (int)0);
-
- /* Draw the view */
- TscErase (screen);
- TdpDraw (info.drawport);
-
- /*
- * Continually poll the cursor checking for button presses that
- * indicate invocation of one of the event request methods.
- */
-
- FOREVER
- {
- location = TloPoll (LOC_POLL);
- key = VOloKey (location);
- if (key == 'q' || key == 'Q')
- break;
-
- /* Let the Event Handler deal with inputs */
- VUerHandleLocEvent (location);
- }
-
- /*
- * Do cleanup stuff -- erase the screen, free dynamic memory, close
- * the display device, and perform final DataViews cleanup.
- */
- VUerClearAll ((OBJECT) 1);
- TdpDestroy (info.drawport);
- TviDestroy (view);
- TscCloseCurrentScreen ();
- TTerminate ();
- return EXIT_OK;
- }
-
- /*
- * PostEvent
- *
- * Service routine for menu input object's service result request which
- * sets up the chosen event request post method for the polygons.
- *
- */
- /*ARGSUSED*/
- LOCAL int
- PostEvent (client, er, label, loc, args)
- OBJECT client;
- EVENT_REQUEST er;
- int label;
- OBJECT loc;
- ADDRESS args;
- {
-
- INFO *info = (INFO *)args;
-
- info->post_mode = (int) (*info->data_ptr);
-
- switch (info->post_mode)
- {
- case RECT_EDGE:
- RectEdge (info);
- break;
- case OBJECT_EDGE:
- ObjectEdge (info);
- break;
- case RECT_EDGE_BUTTON_PRESS:
- RectEdge_ButtonPress (info);
- break;
- case OBJECT_EDGE_KEY_PRESS:
- ObjectEdge_KeyPress (info);
- break;
- case RECT_EDGE_BUTTON_KEY_PRESS:
- RectEdge_ButtonKeyPress (info);
- break;
- }
-
- return (int) INPUT_USED;
- }
-
- /*
- * DrawMark
- *
- * Fill the mark object of a selected polygon
- *
- */
- /*ARGSUSED*/
- LOCAL int
- DrawMark (client, er, label, loc, args)
- OBJECT client;
- EVENT_REQUEST er;
- int label;
- OBJECT loc;
- ADDRESS args;
- {
- ATTRIBUTES attr;
- INFO *info = (INFO *)args;
-
- TdpDrawObject (info->drawport, bound_box[label]);
-
- VOobAtGet (info->mark[label], &attr);
- if (attr.fill_status != mark_state[label])
- {
- TdpEraseObject (info->drawport, info->mark[label]);
- attr.fill_status = mark_state[label];
-
- VOobAtSet (info->mark[label], &attr);
- TdpDrawObject (info->drawport, info->mark[label]);
- }
-
- return (int) INPUT_USED;
- }
-
- /*
- * ClearMark
- *
- * Clear the mark object of a selected polygon is unselected
- *
- */
- /*ARGSUSED*/
- LOCAL int
- ClearMark (client, er, label, loc, args)
- OBJECT client;
- EVENT_REQUEST er;
- int label;
- OBJECT loc;
- ADDRESS args;
- {
- ATTRIBUTES attr;
- INFO *info = (INFO *)args;
-
- TdpEraseObject (info->drawport, bound_box[label]);
-
- VOobAtGet (info->mark[label], &attr);
- if (attr.fill_status != init_state[label])
- {
- TdpEraseObject (info->drawport, info->mark[label]);
- attr.fill_status = init_state[label];
-
- VOobAtSet (info->mark[label], &attr);
- TdpDrawObject (info->drawport, info->mark[label]);
- }
-
- return (int) INPUT_USED;
- }
-
- /*
- * GetBoundBox
- *
- * Get each polygon's bounding box
- *
- */
- LOCAL void
- GetBoundBox (info, bound_box)
- INFO *info;
- OBJECT bound_box[];
- {
- RECTANGLE wvp, svp_delta, svp;
- ATTRIBUTES attr;
- OBJECT pt_obj1, pt_obj2;
- int i;
-
- for (i = 0; i < NUM_OF_TEST_POLY; i++)
- {
- VOobBox (info->poly[i], &wvp, &svp_delta);
-
- TdpWorldToScreen (info->drawport, &wvp.ll, &svp.ll);
- TdpWorldToScreen (info->drawport, &wvp.ur, &svp.ur);
-
- VOobAtGet (info->poly[i], &attr);
- attr.line_type = (char) 2;/* Any line type except SOLID_LINE(1) */
- attr.fill_status = EDGE;
- attr.line_width = (char) 1;
-
- pt_obj1 = VOptCreate (WORLD_COORDINATES, wvp.ll.x, wvp.ll.y, (OBJECT) 0);
- pt_obj2 = VOptCreate (WORLD_COORDINATES, wvp.ur.x, wvp.ur.y, (OBJECT) 0);
-
- bound_box[i] = VOreCreate (pt_obj1, pt_obj2, &attr);
- }
- }
-
- /*
- * RectEdge
- *
- * Post the event request to select an object base on the position of
- * the mouse pointer and the edge detection of the object's bounding box
- *
- */
- LOCAL void
- RectEdge (info)
- INFO *info;
- {
- RECTANGLE wvp, svp, svp_delta;
- int i;
-
- VUerClearAll ((OBJECT) 2);
-
- for (i = 0; i < NUM_OF_TEST_POLY; i++)
- {
- VOobBox (info->poly[i], &wvp, &svp_delta);
- TdpWorldToScreen (info->drawport, &wvp.ur, &svp.ur);
- TdpWorldToScreen (info->drawport, &wvp.ll, &svp.ll);
- VOuVpSort (&svp);
- VUerBoundaryEventPost ((OBJECT) 2, VCAST DrawMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_POS_EVENT,
- &svp, (int) (int)V_INSIDE);
- VUerBoundaryEventPost ((OBJECT) 2, VCAST ClearMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_POS_EVENT,
- &svp, (int) (int)V_OUTSIDE);
- }
- }
-
- /*
- * ObjectEdge
- *
- * Post the event request to select an object base on the position of
- * the mouse pointer and the edge detection of the object's edges
- *
- */
- LOCAL void
- ObjectEdge (info)
- INFO *info;
- {
- int i;
-
- VUerClearAll ((OBJECT) 2);
-
- for (i = 0; i < NUM_OF_TEST_POLY; i++)
- {
- VUerBoundaryEventPost ((OBJECT) 2, VCAST DrawMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_OPOS_EVENT, info->poly[i],
- (OBJECT)TdpGetXform (info->drawport, DR_TO_SCREEN),
- (int)V_INSIDE);
- VUerBoundaryEventPost ((OBJECT) 2, VCAST ClearMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_OPOS_EVENT, info->poly[i],
- (OBJECT)TdpGetXform (info->drawport, DR_TO_SCREEN),
- (int)V_OUTSIDE);
- }
- }
-
- /*
- * RectEdge_ButtonPress
- *
- * Post the event request to select an object base on
- * 1. the position of the mouse pointer, and
- * 2. a mouse button press, and
- * 3. the edge detection of the object's bounding box.
- *
- */
- LOCAL void
- RectEdge_ButtonPress (info)
- INFO *info;
- {
- RECTANGLE wvp, svp, svp_delta;
- int i;
-
- VUerClearAll ((OBJECT) 2);
-
- for (i = 0; i < NUM_OF_TEST_POLY; i++)
- {
- VOobBox (info->poly[i], &wvp, &svp_delta);
- TdpWorldToScreen (info->drawport, &wvp.ur, &svp.ur);
- TdpWorldToScreen (info->drawport, &wvp.ll, &svp.ll);
- VOuVpSort (&svp);
- VUerBoundaryEventPost ((OBJECT) 2, VCAST DrawMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_BRE_EVENT, V_BUTTONPRESS,
- buttonsyms, &svp, (int)V_INSIDE);
- VUerBoundaryEventPost ((OBJECT) 2, VCAST ClearMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_BRE_EVENT, V_BUTTONPRESS,
- buttonsyms, &svp, (int)V_OUTSIDE);
- }
- }
-
- /*
- * ObjectEdge_KeyPress
- *
- * Post the event request to select an object base on
- * 1. the position of the mouse pointer, and
- * 2. a key press of keys defined in keysyms_1 array, and
- * 3. the edge detection of the object's edges.
- *
- */
- LOCAL void
- ObjectEdge_KeyPress (info)
- INFO *info;
- {
- int i;
-
- VUerClearAll ((OBJECT) 2);
-
- for (i = 0; i < NUM_OF_TEST_POLY; i++)
- {
- VUerBoundaryEventPost ((OBJECT) 2, VCAST DrawMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_DOE_EVENT, V_KEYPRESS,
- keysyms_1, info->poly[i],
- (OBJECT)TdpGetXform (info->drawport, DR_TO_SCREEN),
- (int)V_INSIDE);
- VUerBoundaryEventPost ((OBJECT) 2, VCAST ClearMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_DOE_EVENT, V_KEYPRESS,
- keysyms_1, info->poly[i],
- (OBJECT)TdpGetXform (info->drawport, DR_TO_SCREEN),
- (int)V_OUTSIDE);
- }
- }
-
-
- /*
- * RectEdge_ButtonKeyPress
- *
- * Post the event request to select an object base on
- * 1. the position of the mouse pointer, and
- * 2. a mouse button press or a key press of keys defined in
- * keysyms_2 array, and
- * 3. the edge detection of the object's bounding box.
- *
- */
- LOCAL void
- RectEdge_ButtonKeyPress (info)
- INFO *info;
- {
- RECTANGLE wvp, svp, svp_delta;
- int i;
-
- VUerClearAll ((OBJECT) 2);
-
- for (i = 0; i < NUM_OF_TEST_POLY; i++)
- {
- VOobBox (info->poly[i], &wvp, &svp_delta);
- TdpWorldToScreen (info->drawport, &wvp.ur, &svp.ur);
- TdpWorldToScreen (info->drawport, &wvp.ll, &svp.ll);
- VOuVpSort (&svp);
- VUerBoundaryEventPost ((OBJECT) 2, VCAST DrawMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_BRE_EVENT, V_BUTTONPRESS,
- buttonsyms, &svp, (int)V_INSIDE);
- VUerBoundaryEventPost ((OBJECT) 2, VCAST DrawMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_BRE_EVENT, V_KEYPRESS,
- keysyms_2, &svp, (int)V_INSIDE);
-
- VUerBoundaryEventPost ((OBJECT) 2, VCAST ClearMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_BRE_EVENT, V_BUTTONPRESS,
- buttonsyms, &svp, (int)V_OUTSIDE);
- VUerBoundaryEventPost ((OBJECT) 2, VCAST ClearMark, (ADDRESS) info,
- (int)sizeof (INFO), i, VUER_BRE_EVENT, V_KEYPRESS,
- keysyms_2, &svp, (int)V_OUTSIDE);
- }
- }
-